package com.java3_8;

public class MyThread5 implements Runnable {
    private int number = 1;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                if (number <= 100) {
                    this.notify();
                    System.out.println(Thread.currentThread().getName() + " --- " + number);
                    number++;
                    try {
                        this.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                } else {
                    //只要有一个线程没完，程序就继续执行
                    this.notify();
                    break;
                }
            }
        }
    }
}
